package com.wx.controller;

import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Max on 2018/4/13.
 */

public class BaseController {

    private HttpServletRequest request;

    private HttpServletResponse response;

    private HttpSession session;


    @ModelAttribute
    public void setReqAndRes(HttpServletRequest request, HttpServletResponse response){
        this.request = request;
        this.response = response;
        this.session = request.getSession();
    }


    public HttpServletRequest getRequest() {
        return request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public HttpSession getSession() {
        return session;
    }

    /**
     * 跳转视图封装类
     * @param viewName 视图名
     * @return ModelAndView
     */
    public ModelAndView toView(String viewName){
        return new ModelAndView(viewName);
    }

}
